import yaml
import os


class ReadYaml:
    def __init__(self,file_path):
        if os.path.exists(file_path):
            self.file_path=file_path
        else:
            print(f"没有找到{file_path}文件")
        self.data=self.read_yaml()

    def read_yaml(self):
        with open(self.file_path,'r',encoding='utf-8') as file:
            test_data=file.read()
            test_datas=yaml.load(test_data,Loader=yaml.FullLoader)
        return test_datas





if __name__ == '__main__':
    # pass
    # def __init__(self, file_path):
    #     # 判断文件是否存在
    #     if os.path.exists(file_path):
    #         self.file_path = file_path
    #     else:
    #         print('没有找到%s文件路径' % file_path)
    #
    #     self.data = self.read_yaml()
    #
    # def read_yaml(self):
    #     with open(self.file_path, 'r', encoding='utf-8')as f:
    #         p = f.read()
    #         return p
    #
    # def get_data(self, key=None):
    #     result = yaml.load(self.data, Loader=yaml.FullLoader)
    #     # 判断key是否存在
    #     if key == None:
    #         return result
    #     else:
    #         return result.get(key)
    # print(os.path.relpath(__file__))
    RY=ReadYaml('/Users/jiayunkong/work_space/pythonProject/data/test_data.yaml')
    print(RY.read_yaml())
